package main.cn.dao.impl;


import main.cn.dao.PetDao;
import main.cn.dao.impl.BaseDao;
import main.cn.pojo.Pet;

import java.util.List;


public class PetDaoImpl extends BaseDao implements PetDao {

    @Override
    public int addPet(Pet _pet) {
        String sql = "insert into pets(id,orderid,state,name,description) values (?,?,?,?,?)";
        return update(sql,_pet.getId(),_pet.getOrderid(),_pet.getState(), _pet.getName(),_pet.getDescription());
    }

    @Override
    public int deletePet(int id) {
        String sql = "delete from pets where id = ?";
        return update(sql,id);
    }

    @Override
    public int updatePet(Pet _pet) {
        String sql = "update pets set orderid=?,state=?,name=?,description=? where id=?";
        return update(sql, _pet.getOrderid(),_pet.getState(),_pet.getName(),_pet.getDescription(),_pet.getId());
    }

    @Override
    public Pet queryPetById(int id) {
        String sql = "select id,orderid,state,name,description from pets where id = ?";
        return queryForOne(Pet.class,sql,id);
    }


    @Override
    public List<Pet> queryPets() {
        String sql = "select id,orderid,state,name,description from pets";
        return queryForList(Pet.class,sql);
    }
}
